package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Appointment;
import cn.wolfcode.domain.Business;
import cn.wolfcode.domain.SystemDictionary;
import cn.wolfcode.qo.JsonResult;
import cn.wolfcode.service.IAppointmentService;
import cn.wolfcode.service.IBusinessService;
import cn.wolfcode.service.ISystemDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class IndexController {
    @Autowired
    private IBusinessService businessService;
    @Autowired
    private ISystemDictionaryService systemDictionaryService;
    @Autowired
    private IAppointmentService appointmentService;

    @RequestMapping("/index")
    public String indexView(Model model) {
        model.addAttribute("tel", "55555");
        Business business = businessService.queryMainBusiness();
        List<SystemDictionary> systemDictionaries = systemDictionaryService.queryBySn("business");
        model.addAttribute("systemDictionaries", systemDictionaries);
        List<Business> businesses = businessService.listAll();
        model.addAttribute("businesses", businesses);
        model.addAttribute("business", business);
        return "index";
    }

    @RequestMapping("/index/appointment")
    @ResponseBody
    public JsonResult save(Appointment appointment) {
        appointmentService.save(appointment);
        return new JsonResult(true,"预约成功");






    }

}
